home *** CD-ROM | disk | FTP | other *** search
- ; DrawNumsInAString.asm
- ;-----------------------
- ; by Mike™ Scanlin 3 Jan 1987
-
- Include Traps.D
-
- Xref DrawNumsInAString,NumToString,FixPtToString,FormNumString
- Xref GetANumber
-
- ;================
- DrawNumsInAString
- ;================
- ; draw a string that may contain implicit formatted numbers
- ; input: stack contains numbers that will be needed and a pointer a
- ; string. The numbers should be pushed on the stack in order
- ; from last to first (so they can be poped off in order from
- ; first to last). The last thing to be pushed on the stack
- ; is the string pointer
- ; Each formatted number within the input string begins with
- ; a '\' and then either an 'i' (for longints) or a 'f' (for
- ; a fixed point number). For fixed points, first push the
- ; fixed point number, then the divisor to be used to calculate
- ; the remainder. The formatting after the 'i' or 'f' is the
- ; same as for the FormNumString routine.
- ; output: a string is drawn
- ; A0,D0 are trashed
-
- MOVEM.L A0-A3/D1-D2,-(SP)
- LEA 28(SP),A3 ;point to first parameter
- MOVE.L A3,-(SP) ;save initial position
- MOVE.L (A3)+,A2 ;string pointer
- @1 MOVEQ #0,D0
- MOVE.B (A2)+,D0
- BEQ.S @10 ;end of string found
- CMPI.B #'\',D0 ;is it a number?
- BEQ.S @2
- MOVE D0,-(SP)
- _DrawChar
- BRA.S @1
- ;we got a number to format
- @2 LEA scratch,A0
- MOVE.B (A2)+,D0
- CMPI.B #'i',D0 ;is it a longint?
- BNE.S @4
- ;handle integers
- MOVE.L (A3)+,D0 ;get longint
- JSR NumToString
- BRA.S @5 ;go format it
- @4 CMPI.B #'f',D0 ;is it a fixed point?
- BNE.S @1 ;if not, ignore it
- ;handle fixed point
- MOVEA.L A2,A1
- ;find out how many decimal places should be passed to FixPtToString
- MOVE.B (A1)+,D0 ;skip comma, if present
- CMPI.B #',',D0
- BEQ.S @4.1
- SUBA #1,A1
- @4.1 JSR GetANumber
- BMI.S @1 ;no quotient present
- MOVE.B (A1)+,D0
- CMPI.B #'.',D0
- BNE.S @4.2
- JSR GetANumber
- MOVE D0,D2
- BPL.S @4.3
- @4.2 MOVEQ #0,D2 ;no remainder
- @4.3 MOVE (A3)+,D1 ;get divisor
- MOVE.L (A3)+,D0 ;get fixed point num
- JSR FixPtToString
- ;do the formatting
- @5 MOVEA.L A2,A1 ;addr of format string
- JSR FormNumString
- MOVEA.L A1,A2 ;point past format string
- MOVE.L A0,-(SP)
- _DrawString
- BRA.S @1
- @10 SUBA.L (SP)+,A3 ;calc len of params
- MOVE A3,D0
- MOVEM.L (SP)+,D1-D2/A0-A3
- MOVE.L (SP)+,A0 ;get return addr
- ADDA D0,SP ;length of parameters
- JMP (A0)
-
- scratch DCB.B 40,0
-